package com.example.huadu_server.landlord.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.huadu_server.landlord.entity.Landlord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface LandlordMapper extends BaseMapper<Landlord> {
    /**
     * 根据邮箱查询房东信息
     * @param email
     * @return
     */
    @Select("SELECT * FROM landlord WHERE email = #{email}")
    Landlord selectByEmail(String email);

    /**
     * 根据id查询房东信息
     * @param id
     * @return
     */
    @Select("SELECT * FROM landlord WHERE id = #{id}")
    Landlord getLandlordById(@Param("id") int id);

    /**
     * 查询房东绩效：统计每个房东的房源发布数量及预约记录数量，帮助评估房东运营情况
     * @return
     */
    @Select("SELECT l.id AS landlordId, l.username AS landlordName, " +
            " (SELECT COUNT(*) FROM house WHERE landlord_id = l.id) AS totalHouses, " +
            " (SELECT COUNT(*) FROM appointment WHERE landlord_id = l.id) AS totalAppointments " +
            "FROM landlord l")
    List<Map<String, Object>> selectLandlordPerformance();
}
